import { useState } from "react";
import { useDialog } from "./useDialog";

export const useTransferDialog = (props) => {

    const dialog = useDialog(props);
    const transfer = useTransfer(props);

    return {
        ...dialog,
        ...transfer,
    };
};

export const useTransfer = ({ props = {} }) => {

    // 源数据
    const [data, setData] = useState(props?.data || []);
    // 已选键值
    const [keys, setKeys] = useState(props?.keys || []);
    // 已选key/value
    const [target, setTarget] = useState(props?.target || []);

    // function onReload(param, callback = undefined) {
    //     param = param || query;
    //     setQuery(param);

    //     props?.reload(param).then(resp => {
    //         let result = resp.data;
    //         if (isPage) {
    //             setData(result.records);
    //             setPagination({
    //                 current: result.pageNo,
    //                 size: result.pageSize,
    //                 total: result.total,
    //             });
    //         } else {
    //             setData(result);
    //         }
    //         typeof callback === 'function' && callback(result);
    //     })
    // }

    return {
        data,
        keys,
        target,
        setData,
        setKeys,
        setTarget,
    }
}